package top.moonkit.rs_pro.patterns.CheckCode;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import top.moonkit.rs_pro.utils.Mu;

import java.util.List;

/**
 * @author moon
 * @since
 */
@Component
public class CheckCodeFactory {


    public static List<CheckCodeService> services;

    @Autowired
    public void setServices(List<CheckCodeService> services) {
        CheckCodeFactory.services = services;
    }

    public static CheckCodeService buildService(String account) {
        return services.stream()
                .filter(
                service -> service.isMe(account)
        )
                .findFirst()
                .orElseThrow(() -> new RuntimeException(Mu.m("login.code_send_fail")));
    }

}
